package com.nidu.demo.dept.convertor;

import com.nidu.demo.base.BaseConvertor;
import com.nidu.demo.convertor.MapStructConfig;
import com.nidu.demo.dept.dto.DepartmentCO;
import com.nidu.demo.dept.dto.DepartmentTreeCO;
import com.nidu.demo.dept.mapper.dataobject.DepartmentDO;
import com.nidu.demo.dept.model.Department;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

@Mapper(config = MapStructConfig.class)
public interface DepartmentConvertor extends BaseConvertor<DepartmentDO, Department, DepartmentCO> {
    
    @Override
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(source = "deptName", target = "name")
    @Mapping(source = "deptCode", target = "code")
    DepartmentDO toDataObject(Department dept);

    @Override
    @Mapping(source = "name", target = "deptName")
    @Mapping(source = "code", target = "deptCode")
    Department toDomainObject(DepartmentDO deptDO);

    /**
     * 转换为树形结构
     */
    DepartmentTreeCO toTreeClientObject(Department dept);

    /**
     * 转换为树形结构列表
     */
    List<DepartmentTreeCO> toTreeClientObjects(List<Department> depts);
}